require('./Listitem.styl');
import { GetQueryString } from 'clientConfig/util/queryurlfield';
import { Control } from 'react-keeper'
const { Boxs, Icon, Badge } = SaltUI;
const { HBox, Box } = Boxs;
var classNames = require('classnames/bind');
let apptype = GetQueryString("apptype");
let devtype = GetQueryString("devtype");
const handleClick = (props) => {
    if (props.refreshing) return;
    if (props.origin.includes("tender") || props.origin.includes("workplan") || props.origin.includes("payment") || props.origin.includes("maintenance")) {
        let field = props.origin.split("/")[1];
        if (field == "singleproject") {
            Control.go('/home/workplan/singleproject/payprogress', { process_id: props.data.process_id, origin: props.origin });
        } else if (field == "notice") {
            let subcontent = props.data.content[props.data.content.length - 1].subcontent;
            if (subcontent != "待审批")
                props.tool = !props.tool;
            Control.go('/home/workplan/pending/detail/' + props.tool, { process_id: props.data.process_id, origin: props.origin });
        } else {
            Control.go('/home/workplan/pending/detail/' + props.tool, { process_id: props.data.process_id, origin: props.origin });
        }
    } else if (props.origin.includes("achievements")) {
        let field = props.origin.split("/")[1];
        let origin_title = props.origin_title
        if (field == "singleproject") {
            Control.go('/home/workplan/singleproject/payprogress');
        } else if (origin_title == '质量管理') {
            Control.go('/home/achievements/quality/manage_detail', { process_id: props.data.process_id });
        } else if (origin_title == '进度跟踪') {
            Control.go('/home/achievements/quality/process_detail', { process_id: props.data.process_id })
        } else if (origin_title == '版本管理') {
            let proj_name = props.data.title;
            let folder_id = props.data.folder_id;
            // Control.go('/home/achievements/quality/version_detail_p', { proj_name,folder_id })
            if (!window.isBp) {
                if (apptype == 0 && devtype == 1) {
                    //手机微应用
                    Control.go('/home/achievements/quality/version_detail_m', { proj_name, folder_id })
                } else if (apptype == 0 && devtype == 2) {
                    //pc微应用
                    Control.go('/home/achievements/quality/version_detail_p', { proj_name, folder_id })
                } else if (DingTalkPC) {

                    if (DingTalkPC.ua.isDesktop) {
                        //pc微应用
                        Control.go('/home/achievements/quality/version_detail_p')
                    } else {
                        Control.go('/home/achievements/quality/version_detail_m')
                    }
                }
            } else {
                Control.go('/home/achievements/quality/version_detail_p', { proj_name, folder_id })
            }
        } else {
            Control.go('/home/workplan/pending/detail' + (!props.tool ? '' : `/${props.tool}`), { process_id: props.data.process_id, origin: props.origin });
        }
    }


    // Control.go('/home/achievements/quality/manage_detail')
    // Control.go('/home/achievements/quality/process_detail')
};
const Listitem = (props) => {
    var styles = {
        msg: 'msg',
        workplan: 'workplan-manage'
    };
    var cx = classNames.bind(styles);
    if (props.className) {
        for (let key in styles) {
            if (props.className.includes(styles[key])) {
                var obj = {};
                Object.assign(obj, { [`${key}`]: true });
            }
        }
    }
    if (JSON.stringify(obj) == "{}") {
        var className = cx('listitem', props.className);
    } else {
        var className = cx('listitem', obj);
    }
    return (
        <div className={className} onClick={() => { handleClick(props) }}>
            <HBox className={classNames({ 'head': true })} vAlign="center">
                {props.data.badge &&
                    <Box>
                        <Badge dot >
                            <div></div>
                        </Badge>
                    </Box>}
                <Box flex={2} >{props.data.title}</Box>
                <Box flex={1}>
                    <h4>{props.data.subtitle && props.data.subtitle.split(" ")[0]}</h4>
                </Box>
            </HBox>
            {props.data.content && props.data.content.map((item, index) => {
                return (<HBox vAlign="center" className={classNames({ 'content': true })} >
                    <Box className={classNames({ contentColor: item.className == "green", contentColor1: item.className == "red" })}>{item.subcontent}</Box>
                    <Box flex={3}>{item.subcontent && item.unitcontent && "："}{typeof item.unitcontent == "number" ? new Date(item.unitcontent).toLocaleDateString() : item.unitcontent}</Box>
                </HBox>
                )
            })}
        </div>
    );
}

module.exports = Listitem;
